﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Client;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace MangoMes.Write.API.Applications.Clientss
{
    public class ClientManagementDeleteHandler : IRequestHandler<ClientManagementDeleteCommand, ResultsDTO>
    {
        private readonly IBateRepository<ClientManagement> client;
        public ClientManagementDeleteHandler(IBateRepository<ClientManagement> client)
        {
            this.client = client;   
        }
        public async  Task<ResultsDTO> Handle(ClientManagementDeleteCommand request, CancellationToken cancellationToken)
        {
            var list = new ResultsDTO() { Code = 0 };
            DapperHelper  helper = new DapperHelper();
            var conn=helper.MangoMesWrite ;
            var str = new ClientManagement();
            var sql = "update clientmanagement set IsNo=1 where ClientId=" + request.ClientId + "";
            var result = client.Add(sql, str, conn);
            if (result!=null)
            {
                list.Code = 1;
                list.Message = "删除成功";
            }
            return list;
        }
    }
}
